#include<iostream>
using namespace std;
const int N = 10010;
int arr[N];
int n, m;
int dis[N];
bool flag[N];
int ans[N][N];
int count1;
void dfs(int step)
{
	if (step == n) {
	
		for (int i = 0; i < n; i++) {
			ans[count1][i] = dis[i];
		}
		count1++;
		return;
	}
	for (int i = 1; i <= n; i++) {
		if (!flag[i]) {
			flag[i] = 1;
			dis[step] = i;
			dfs(step + 1);
			flag[i] = 0;
			dis[step] = 0;
		}
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	dfs(0);
	int index = 0;
	for (int i = 0; i < count1 - 1; i++) {
		int flag = 1;
		for (int j = 0; j < n; j++) {
			if (arr[j] != ans[i][j]) {
				flag = 0;
			}
		}
		if (flag) {
			index = i;
			break;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ans[index + m][i] << " ";
	}
	return 0;
}